package com.pine.dcts.common;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 统一客户端返回格式
 *
 * @author dcits.xyjxust
 *         Date 2017年8月23日
 */
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    //状态码
    private Integer code;
    //状态
    private boolean success;
    //信息
    private String message;
    //数据
    private T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = (code == HttpStatus.OK.value() ? true : false);
    }


    public static <T> Result success(T data){
        return new Result(200,"处理成功",data);
    }
    public static   Result success(){
        return new Result(200,"处理成功",null);
    }

    public static <T>  Result error(String message, T data){
        return new Result(500,message,data);
    }
    public static  Result error(String message){
        return new Result(500,message,null);
    }
    public static <T>  Result error(int code,String message, T data){
        return new Result(code,message,data);
    }
    public static <T>  Result error(int code,String message){
        return new Result(code,message,null);
    }




}
